﻿using System;
using System.ComponentModel;

namespace Daun.Cores.Entities
{
    public class DocumentPropertyConverter : TypeConverter 
    {
        public override bool GetPropertiesSupported(ITypeDescriptorContext context)
        {
            return true; 
        }
        public override PropertyDescriptorCollection GetProperties(ITypeDescriptorContext context, object value, System.Attribute[] attributes)
        {            
            DocumentProperty item = (DocumentProperty)value;
            string[] keys = item.GetKeys();
            PropertyDescriptor[] props = Array.ConvertAll(
                keys, key => new DocumentPropertyDescriptor(key,item.DocumentCategory));
            
            return new PropertyDescriptorCollection(props, true);
        }
    }
}
